<?php
// ini_set("error_reporting", E_ALL);
// ini_set("display_errors","1"); 
// ini_set("ignore_repeated_errors","1");
// ini_set("log_errors", "1" ); 
// ini_set("error_log", "articles/errors_recherche.txt" );
$TODO = "";


include ('php/Lib_Liste.php');
include ('php/Lib_Read.php');
include ('php/Lib_Write.php');

$tmp_recherche = '';
$tmp_liste ='';
$extrait ='';

$str='';
$strg='';
$strgg='';

$Nb_art = nb_articles();
links("data/art");
$nb = sizeOf($GLOBALS['liste_articles']);
$Echo  = "<ul><li id=\"categories\">
					<h2>$nb articles in Ouikimedia</h2>
					<ul>";
	if ($Nb_art !=0) {
		if (isset($_POST['recherche'])) {
			$tmp_recherche = $_POST['recherche'];
			if ($tmp_recherche !=''){
				for ($i=0; $i != sizeOf($GLOBALS['liste_articles'])  ; $i++){
					$tmp_liste = $GLOBALS['liste_articles'][$i];
					$str = strtolower($tmp_recherche);
                    $strg = strtolower($tmp_liste);
					$strgg = substr_count($strg, $str);
					$strggg = substr_count($str, $strg);
					
					if (( $strgg >= 1 ) || ($strggg >= 1)) {
						$extrait = extrait_article($tmp_liste);
						$extrait = RemoveCode($extrait);
						$titre = ucwords($tmp_liste);
						$Echo .= "<li><a href='article.php?article=$tmp_liste'>$titre</a>
            <br/>&nbsp;&nbsp;&nbsp;&nbsp;
					  $extrait
            <a href='article.php?article=$tmp_liste'>article.php?article=$tmp_liste</a>
            </li><br/>";
            $Echo_left .="<ul><a href='article.php?article=$tmp_liste'>$titre</a></ul>";
					}
				}
			}
			else {
				for ($i=0; $i != sizeOf($GLOBALS['liste_articles'])  ; $i++){
					$tmp_liste = $GLOBALS['liste_articles'][$i];
					$extrait = extrait_article($tmp_liste);
					$extrait = RemoveCode($extrait);
					$titre = ucwords($tmp_liste);
					$Echo .= "<li><a href='article.php?article=$tmp_liste'>$titre</a>
            <br/>&nbsp;&nbsp;&nbsp;&nbsp;
					  $extrait
            <a href='article.php?article=$tmp_liste'>article.php?article=$tmp_liste</a>
            </li><br/>";
          $Echo_left .="<ul><a href='article.php?article=$tmp_liste'>$titre</a></ul>";
				}
			}
			$Echo .= "</ul></li></ul>";
		}
	}
	else {
		$Echo .="No match found !";
	}

include('template/top.tpl');
include('template/main.tpl');
include('template/back.tpl');
?>
